package de.core;

import javax.swing.JFrame;

import de.core.gameplay.level.AbstractLevel;
import de.game.level.TestLevel;

public class GameFrame extends JFrame {
    private static GameFrame instance;
    private GameThread gameThread;

    public GameFrame() {
//        setUndecorated(true);
        setIgnoreRepaint(true);

//        GraphicsDevice graphicsDevice = getGraphicsConfiguration().getDevice();
//        graphicsDevice.setFullScreenWindow(this);
//        graphicsDevice.setDisplayMode(new DisplayMode(640, 480, DisplayMode.BIT_DEPTH_MULTI, 60));

        setDefaultCloseOperation(EXIT_ON_CLOSE);

        setVisible(true);
        pack();

        createBufferStrategy(2);
        gameThread = new GameThread(getBufferStrategy());
    }

    public static GameFrame getInstance() {
        if (instance == null) {
            instance = new GameFrame();
        }
        return instance;
    }

    public GameThread getGameThread() {
        return gameThread;
    }

    @Override
    protected void finalize() throws Throwable {
        gameThread.stop();
    }

    public static void main(String[] args) {
        GameFrame gameFrame = GameFrame.getInstance();
        AbstractLevel level = new TestLevel();

        gameFrame.setSize(level.getWidth(), level.getHeight());
        gameFrame.getGameThread().setCurrentLevel(level);
        gameFrame.getGameThread().start();
    }
}
